package cn.shu.Strategy;

/**
 * Created by 76062 on 2017/9/22.
 */
public class Context {

    LocStrategy locStrategy;

    public Context(Integer machineCode) {
        init(Machine.getStrategy(machineCode));
    }

    private void init(LocStrategy locStrategy) {
        this.locStrategy = locStrategy;
    }

    public void getLoc(){
        locStrategy.getLoc();
    }

    enum Machine {
        GPS(new GPS(),1),Galileo(new Galileo(),2),BeiDou(new BeiDou(),3);

        private LocStrategy locStrategy;
        private Integer code;

        private Machine(LocStrategy locStrategy, Integer code) {
            this.locStrategy = locStrategy;
            this.code = code;
        }

        public static LocStrategy getStrategy(Integer code) {
            if(code == null){
                return  null;
            }
            for (Machine c : Machine.values()) {
                if (code.equals(c.getCode())){
                    return c.locStrategy;
                }
            }
            return null;
        }

        public LocStrategy getLocStrategy() {
            return locStrategy;
        }

        public void setLocStrategy(LocStrategy locStrategy) {
            this.locStrategy = locStrategy;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }
    }
}


